﻿package mortal.game.view.drugBack
{
    import Message.DB.Tables.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.shopMall.view.*;
    import mortal.mvc.core.*;

    public class DrugItemCellRenderer extends GCellRenderer
    {
        private var _shopItem:ShopSellItem;
        private var _propName:GTextFiled;
        private var _moneyTxt:GTextFiled;
        private var _moneyIcon:GBitmap;
        private var _buyBtn:GButton;
        private var _numericStepper:GNumericStepper;

        public function DrugItemCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:GTextFormat = null;
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(0, 0, 225, 107, this, ImagesConst.ItemBuyBg));
            this.pushUIToDisposeVec(UIFactory.bg(0, 22, 215, 1, this, ImagesConst.SplitLine));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35281), 98, 26, 40, 20, this, GlobalStyle.textFormatAnHuan));
            _loc_1 = GlobalStyle.textFormatPutong;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            this._propName = UIFactory.gTextField("", 63, 1, 100, 25, this, _loc_1, true);
            _loc_1.align = TextFormatAlign.LEFT;
            this._moneyTxt = UIFactory.gTextField("", 130, 26, 100, 20, this, _loc_1);
            this._moneyIcon = UIFactory.gBitmap("", 170, 25, this);
            this._shopItem = UICompomentPool.getUICompoment(ShopSellItem);
            this._shopItem.x = 15;
            this._shopItem.y = 26;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._shopItem);
            this._buyBtn = UIFactory.gButton(Language.getString(35282), 96, 74, 80, 24, this, "DrugItemBtn");
            this._buyBtn.drawNow();
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            _loc_1.align = AlignMode.RIGHT;
            this._numericStepper = UIFactory.gNumericStepper(100, 50, 42, 20, this, 99, 1, "NumericStepper", _loc_1);
            this._numericStepper.value = 1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._shopItem.dispose(param1);
            this._buyBtn.dispose(param1);
            this._propName.dispose(param1);
            this._numericStepper.dispose(param1);
            this._moneyTxt.dispose(param1);
            this._moneyIcon.dispose(param1);
            this._shopItem = null;
            this._buyBtn = null;
            this._propName = null;
            this._numericStepper = null;
            this._moneyTxt = null;
            this._moneyIcon = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var e:* = event;
            var callback:* = function () : void
            {
                _shopItem.shopItemData.num = _numericStepper.value;
                _shopItem.shopItemData.type = _shopItem.shopItemData.tShopSell.isBindMoney;
                var _loc_1:* = DrugPackUtil.isCanUseDrugItem(_shopItem.itemData);
                _shopItem.shopItemData.useNum = _loc_1 > _shopItem.shopItemData.num ? (_shopItem.shopItemData.num) : (_loc_1);
                Dispatcher.dispatchEvent(new DataEvent(EventName.BuyItem, _shopItem));
                return;
            }// end function
            ;
            var html:* = Language.getStringByParam(35283, this._numericStepper.value, this._shopItem.itemData.name, this._shopItem.shopItemData.prize * this._numericStepper.value + GameDefConfig.instance.getEPrictUnitName(this._shopItem.shopItemData.tShop.unit));
            TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.buyDrugItemWin, callback, html, null, Alert.OK | Alert.CANCEL);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            if (this._shopItem.shopItemData == param1)
            {
                return;
            }
            this._numericStepper.value = 1;
            this._shopItem.shopItemData = param1 as ShopItemData;
            this._propName.htmlText = ItemsUtil.getItemName(this._shopItem.itemData);
            this._moneyTxt.text = this._shopItem.shopItemData.prize.toString();
            var _loc_2:* = ShopConfig.instance.getTShopByCode(this._shopItem.shopItemData.tShopSell.shopCode) as TShop;
            this._moneyIcon.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(_loc_2.unit));
            this._moneyIcon.x = this._moneyTxt.x + this._moneyTxt.textWidth + 5;
            return;
        }// end function

    }
}
